function deleteID(e){
	var targetID = getRowId(e.target);
	var tr = findUpElement(e.target, "tr");
	$("#deleteBox form input#id").attr("value",targetID);
	$("#deleteBox form input#datatableName").attr("value",$("#mainDataTable").attr("datatableName"));
	var inputList = $("#deleteBox form input[type='text']");
	var dataList = $(tr).children("td");
	for(var i = 0; i < inputList.size(); i++){
		inputList[i].value = $(dataList[i]).text();
	}
	$('#deleteBox').dialog({ title: "删除项目"});
}

$("table.datatable td div.operatorDelete").click(deleteID);

$(document).ready(function(){
  var th = $("table#mainDataTable thead th[fieldname='checkButton']");
  $(th).find("div.thOpContainer").append("<input type='checkbox' id='allCheck'>");
  $(th).find("input#allCheck").change(function(){
    var allCheckBoxs = $("table#mainDataTable tbody tr td input.operatorCheck");
    if($(th).find("input#allCheck")[0].checked == true){
      $(allCheckBoxs).attr("checked",true);
    } else {
      $(allCheckBoxs).attr("checked",false);
    }
  });
  var deleteButton = $("<div class='deleteButton'>删</div>").appendTo($(th).find("div.thOpContainer"));
  $(deleteButton).click(function(){
    var allCheckRows =  $("table#mainDataTable tbody tr").has("td>:checkbox[checked='true'].operatorCheck");
    
    if(allCheckRows.size() > 0){
      allCheckRows.css("background-color","red");
      var data = {};
      for(i=0;i<allCheckRows.size();i+=1){
        var prefix = "$RD_" + "$"+i+"_";
        var name = prefix + "id";
        data[name] = getRowId(allCheckRows[i]);
      }
      var url = '/Table/Table.do';
      data["method"] = 'delete';
      data["datatableName"] = getTableName(allCheckRows[0]);
      $.post(url,data);
    }
  });
});

